package com.nondo.dean.uniqueid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration//开启配置
@EnableConfigurationProperties(UniqueIdProperties.class)//开启使用映射实体对象
public class UniqueIdAutoConfiguration {

    @Autowired
    private UniqueIdProperties uniqueIdProperties;

    @Bean
    @ConditionalOnMissingBean(UniqueId.class)
    public UniqueId uniqueId() {
        return new UniqueId(uniqueIdProperties.getWorkerId(), uniqueIdProperties.getDataCenterId());
    }

}
